import requests
from bs4 import BeautifulSoup


def get_html(url):
    res = requests.get(url)
    res.encoding = 'utf-8'
    with open('books_page.html', 'w') as file:
        file.write(res.text)


def get_books():
    content_dict = {}
    with open('books_page.html', 'r', encoding='utf-8') as file:
        res = file.read()

    soup = BeautifulSoup(res, 'lxml')
    block_books = soup.find('div', class_='blist-biglist')
    books = block_books.find_all('div', class_='book-item-manage')
    for book in books:
        book = book.find('div', class_='block-border card-block brow').find('div')
        img = book.find('div', class_='brow-cover').find('div').find('a').find('img').get('src')
        print(img)
        main_content = book.find('div', class_='brow-data').find('div')
        href_title_tag = main_content.find('a', class_='brow-book-name with-cycle')

        href = href_title_tag.get('href')
        title = href_title_tag.text

        href_name_author = main_content.find('a', class_='brow-book-author')

        href_author = href_name_author.get('href')
        title_author = href_name_author.text
        print(title_author)

        content_dict[title] = {
            'href': href,
            'href author': href_author,
            'name author': title_author,
            'book cover': img
        }

    return content_dict
